﻿using AdminStyem.Application.Command.ProcessingCommand;
using AdminStyem.Application.DTO;
using AdminStyem.Domain.Entity.Boss;
using AdminStyem.Repositories;
using MediatR;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AdminStyem.Application.CommandHandler.ProcessingCommandHandler
{
    public class ProcessingFirmShowCommandHandler : IRequestHandler<ProcessingFirmShowCommand, APIResult<List<ProcessingFirmDTO>>>
    {
        IBaseRespository<ProcessingFirm> BaseProcessingfirm;

        public ProcessingFirmShowCommandHandler(IBaseRespository<ProcessingFirm> baseProcessingfirm)
        {
            BaseProcessingfirm = baseProcessingfirm;
        }

        public Task<APIResult<List<ProcessingFirmDTO>>> Handle(ProcessingFirmShowCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<ProcessingFirmDTO>> ret = new APIResult<List<ProcessingFirmDTO>>();
            var firms = BaseProcessingfirm.Queryable()
                                          .Select(f => new ProcessingFirmDTO
                                          {
                                              ProcessingFirmId = f.ProcessingFirmId,
                                              FirmName = f.FirmName,
                                              ProductionNo = f.ProductionNo,
                                              FirmPhoto = f.FirmPhoto,
                                              IsDeleted = f.IsDeleted
                                          }).ToList();

            ret.Data = firms;
            ret.Code = ResultCode.查询成功;
            ret.Message = ResultCode.查询成功.ToString();

            return Task.FromResult(ret);
        }
    }
}
